Skip to content

fix: stop a leftover connection test announcing after adding a gateway - #2438

Merged
shanselman merged 6 commits into
mainfrom
shanselman-fix-probe-after-add-form-closes
Dec 2, 2026
Merged

shanselman merged 6 commits into
mainfrom
shanselman-fix-probe-after-add-form-closes

Conversation

@shanselman

@shanselman shanselman commented Dec 2, 2026 •

Copy link
Copy Markdown
Collaborator

Agent assessment

Self-reported assessment, not an independent review.

Assessed revision: 3447f756e7d98b34d560a7f655e19502d8b3432e

Dimension Assessment Rationale
Change confidence 9/10 ↑ build.ps1, Shared (6279 passed) and Tray (7403 passed) suites pass locally.
↑ Review findings fixed, each with a red/green check: Unloaded now clears the text, a failed /health keeps the base status, the Stop test uses pre-buffered content and fails if the final cancellation check is removed, and the save-path guards fail if Stop moves before the save await.
↑ Replaced token sources are disposed; Stop rechecks cancellation before sending /health.
↑ The base response is disposed before the /health await. A test holds /health past Stop and then returns 200: it fails on the previous head (base not disposed) and when the final guard is removed (a result is reported).
↑ Mounted run of this head in a Sandbox guest with NVDA Speech Viewer (evidence): leaving the page while a probe was held produced no result text, no /health request and no speech; a fresh edit after returning was spoken.
↓ Save and Cancel/Back were not run mounted; source guards and unit tests cover them. Speech Viewer text is not audible output.
↑ The test is also gated on IsLoaded, so a LostFocus after Unloaded cannot start one; the source guard fails without it.
↑ CI Gate green on this head after one rerun of an unrelated WSL Gateway restart E2E (Gateway state database held by its maintenance process).
Diagnosis confidence 8.5/10 ↑ OnDirectUrlLostFocus calls ScheduleConnectivityTest with no Add-form check, after the save path has already stopped the probe.
↓ Reported by landing reviewers from source; not reproduced at runtime.
Evidence fit 8/10 ↑ Matches the reviewers' MEDIUM finding on #2433.
↓ No user report or trace of a late announcement in the field.

Follows up #2433. Related: #1946

What Problem This Solves

After a successful Save & connect on the Add gateway form, the URL box can still have focus. When the form closes, that box loses focus, starts one more connection test, and a screen reader then hears a stale "Cannot reach gateway" or similar result for a form that's already gone.

User Impact

User impact: screen reader users no longer hear a leftover connection-test result after adding a gateway.

Why This Change Was Made

The connection test is now only scheduled while the Add gateway form is open, and a test already running when the form closes no longer announces its result. The discovered-gateway "Add" button now marks the form as open before filling in the URL, so its test still runs. The connection-test lifecycle moved from the page into a small WinUI-free owner, AddGatewayConnectivityTest, so it can be tested directly, and switching to a saved gateway now stops a pending test too.

Evidence

  • .\build.ps1: all builds succeeded.
  • Shared tests: 6279 passed, 0 failed, 28 skipped. Tray tests: 7403 passed, 0 failed (excluding SettingsManagerIsolationTests.OpenClawTrayDataDirRedirectsSettingsAwayFromRealAppData, which reads the real roaming profile).
  • AddGatewayConnectivityTestTests uses a fake HTTP handler that holds the request until released. It shows that a test stopped (Back/Save) or whose form closed while in flight reports nothing, that scheduling while the form is closed starts no request, and that an HttpClient timeout reports Unreachable. Red check: making Stop() a no-op fails the stop test, and removing the open-form gate fails the form-closed tests.
  • Source tests check that the page passes the Add-form state to the owner, that the discovered-gateway Add sets the form open before filling the URL, and that Back, Save and switching to a saved gateway stop the test.
  • Review fixes at this head: leaving the page clears the test text, a failed /health fallback keeps the base Gateway responded with N status as on main, and replaced token sources are disposed. BaseErrorStatusThenHealthFailure_ReportsTheBaseStatus and the Unloaded guard failed before the fix and pass after. Removing the final cancellation check fails the pre-buffered Stop test, and moving Stop before the save await fails the ordered save-path guard. Added a ledger row for AddGatewayConnectivityTest in docs/ARCHITECTURE.md. The base response is now disposed before the /health await; StoppedDuringHealthFallback_ShowsNothingAndDisposesTheBaseResponse holds /health past Stop, then returns 200, and asserts nothing is reported.
  • Mounted proof on this head (Sandbox, NVDA 2026.3.1 Speech Viewer): leaving the page during a pending probe shows and speaks nothing, and a fresh edit after returning still reports. See this comment.
  • Not verified: a mounted run of Save or Cancel/Back during a pending probe, and audible speaker output.

Required proof pools

  • windows-winui-interactive: Add gateway connection-test announcements changed.

Follows up #2433. LostFocus on the URL box can fire after a successful
save collapses the form; ScheduleConnectivityTest now returns unless the
Add form is open. The debounce delay moves inside the try so its
cancellation is observed.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@clawsweeper

clawsweeper Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

🦞👀
Pull request received.

ClawSweeper review complete

ClawSweeper finished reviewing this revision.

View the workflow run.

@clawsweeper clawsweeper Bot added P2 Normal priority bug or improvement with limited blast radius. impact:ux-friction User-facing flow adds avoidable confusion or support burden without fully blocking progress. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Dec 2, 2026
@clawsweeper

clawsweeper Bot commented Dec 2, 2026

Copy link
Copy Markdown

Codex review: passed.

What this changes

The PR prevents connectivity tests from starting after the Add gateway form closes and catches cancellation during the debounce delay.

Example: Save a gateway at ws://127.0.0.1:18789 while the URL box retains focus, then let the form collapse.

  • Before: The resulting LostFocus event can schedule another probe and announce its result after the form closes.
  • After: The scheduler sees that Add gateway mode has ended and returns without starting another probe.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) A focused, apparently correct repair with reported negative-control validation and supporting CI, but only source-level evidence for the changed lifecycle behavior.
Proof confidence 🦐 gold shrimp (3/6) Exempt from the contributor proof gate: supplied evidence is source-contract validation, while successful-save focus ordering and screen reader silence remain unverified at runtime.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A screen reader can announce a connectivity result for an Add gateway form that has already closed after saving.
Reason: The maintainer-authored direction completes the existing stop-on-close contract with a small change and preserves connectivity feedback while adding or editing gateways.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-authored PR fixes a concrete lifecycle gap still present on main, and no introduced correctness defect was found.

Reviewed head: 63776c7689591311427a433e1bbac57ccaa23721

Before merge

None.

Findings

None.

Agent review details

How this fits together

ConnectionPage receives URL edits, focus events and decoded setup URLs, schedules an HTTP connectivity probe, and presents its result through status text and a screen reader announcement.

flowchart LR
    A[URL or setup code input] --> B[ConnectionPage scheduler]
    B --> C[Add gateway state check]
    C --> D[Debounced HTTP probe]
    D --> E[Result text]
    E --> F[Screen reader announcement]
Loading

Technical review

Best possible solution:

Land the focused scheduler guard, discovery ordering correction and cancellation handling through the existing ConnectionPage lifecycle.

Do we have a high-confidence way to reproduce the issue?

Main's save-to-None transition and unguarded LostFocus scheduler establish the reported path in source, but actual WinUI focus ordering and a late spoken result were not reproduced.

Is this the best way to solve the issue?

The change fixes admission at the existing scheduler, preserves active-form callers and observes debounce cancellation without adding state, wrappers or a parallel owner.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 3240ab1ddb31.

Provenance checked

  • Debounced connectivity scheduling and cancellation keeps the original intent (eecc97e: Automatically test URL input and decoded setup URLs with a debounce; the patch retains that behavior while restricting it to the owning form's lifetime.)
  • Discovered-gateway form entry keeps the original intent (672aadc: The Connection page rebuild provided a discovered-gateway Add action that prefills the direct form for Save & connect.)
  • Announcement suppression after leaving the form keeps the original intent (3240ab1: Announce connectivity results while cancelling pending work on Back and save so closed forms produce no stale feedback.)

Testing

Proof path: unit tests only.

Security

None.

Evidence

What I checked:

Likely related people:

  • Scott Hanselman: Raw commit 3240ab1 adds src/OpenClaw.Tray.WinUI/Pages/ConnectionPage.xaml.cs:2864 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 3240ab1ddb31; files: src/OpenClaw.Tray.WinUI/Pages/ConnectionPage.xaml.cs)
  • Ranjesh Jaganathan: Raw commit eecc97e adds src/OpenClaw.Tray.WinUI/Pages/ConnectionPage.xaml.cs:1596 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: eecc97e3b09f; files: src/OpenClaw.Tray.WinUI/Pages/ConnectionPage.xaml.cs)

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall readiness starts with the lower of the proof and patch scores. It is capped at 3/6 if the fix is partial, the change offers little benefit, a product decision is still open, or the PR reverses an earlier decision without saying why. ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed December 1, 2026, 11:02 PM ET / December 2, 2026, 04:02 UTC.

shanselman and others added 5 commits December 1, 2026 20:54
Re-checks the Add-form intent before announcing a probe result, and pins
the discovered-gateway intent-before-URL order with a source test.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Move the Add gateway probe lifecycle into AddGatewayConnectivityTest so it can be tested without WinUI. Behavioral tests hold a request in flight through Stop and a form close, then release it and assert nothing is reported. Also stop the probe when switching to a saved gateway.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…nload

- OnPageUnloaded uses StopConnectivityTest so stale text is cleared.
- A failed /health fallback keeps the base non-2xx status, as before the extraction.
- Stop rechecks cancellation before /health and disposes replaced token sources.
- Tests: pre-buffered Stop fake, ordered save-path guards, base-status test, ledger row.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
- Record the base error status and dispose the base response before awaiting /health,
  so a Stop during the fallback leaves nothing undisposed.
- Test: base 503, /health held past Stop then 200, reports nothing and disposes the base.
- Source guards: Stop clears and collapses the text; Save stop sits in the success branch.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Unloaded keeps the Add intent, so gate the test on IsLoaded too. Correct the
ledger row: the base status is kept only when /health throws.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@shanselman

Copy link
Copy Markdown
Collaborator Author

Hi, I'm a Copilot triage agent (not Scott) posting mounted-UI proof for head 3447f756e7d98b34d560a7f655e19502d8b3432e. No code changed.

Setup: a disposable Windows Sandbox guest running the real Companion app built from this head, connected to the offline fixture Gateway. Portable NVDA 2026.3.1 (official installer, Authenticode signed by NV Access) ran with Speech Viewer and its I/O speech log. A small guest-only TCP listener on 127.0.0.1:18999 accepts connections and never replies, so the probe stays pending until its 5 s timeout. The listener logs each accepted connection.

Step Observed
Baseline: stay on the page Set the URL to ws://127.0.0.1:18999. The listener accepted the base request at 00:47:52 and /health at 00:47:57. NVDA spoke "✗ Cannot reach gateway" at 00:48:02.
1. Leave while pending Set the URL to ws://127.0.0.1:18999/. UIA showed AddTestResultText = "Testing connection…". The base request was accepted at 00:48:12, and I opened Settings > Systems before it timed out.
2. Nothing after leaving The listener saw no further connections: no /health request, so the probe was cancelled. Waited 30+ s. NVDA's only speech was the Systems page's own InfoBar at 00:48:17, with no "Cannot reach" or other result. Back on Connection, the Add form was closed and AddTestResultText was absent from the UIA tree.
3. Return and edit again Reopened Add gateway and edited the URL to the fixture endpoint at 00:49:24.5. NVDA spoke "✗ Cannot reach gateway" at 00:49:25.5, and the text was visible on the form.

Limits: NVDA's Speech Viewer and log show what NVDA was asked to speak, not audible speaker output. Cancel/Back and Save are not exercised here; those paths keep their unit and source-guard coverage. The screenshots and a 2-minute recording are kept as session artifacts.

@shanselman
shanselman merged commit 8393459 into main Dec 2, 2026
57 of 60 checks passed
@shanselman
shanselman deleted the shanselman-fix-probe-after-add-form-closes branch December 2, 2026 08:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

impact:ux-friction User-facing flow adds avoidable confusion or support burden without fully blocking progress. P2 Normal priority bug or improvement with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant